package tech.xs.sys.domain.entity;


import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import tech.xs.common.framework.domain.entity.BaseEntity;
import tech.xs.common.framework.domain.enums.DataSourceTypeEnum;
import tech.xs.common.framework.domain.exception.InvalidParameterException;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static tech.xs.common.util.pattern.CommonPattern.NUMERIC_LETTER_128;

/**
 * SysChildDict
 *
 * @author 沈家文
 * @since 2023/5/11 16:56
 */
@Getter
@Setter
@ToString
@TableName("sys_child_dict")
public class SysChildDict extends BaseEntity {

    private String code;

    private String name;

    private Long dictId;

    private DataSourceTypeEnum source;

    private String remark;

    @TableField(exist = false)
    private List<SysChildDictData> datas;

    public static void checkCode(String code, String fieldName) {
        Matcher m = NUMERIC_LETTER_128.matcher(code);
        if (!m.matches()) {
            throw new InvalidParameterException(fieldName, "编码只能是大小写字母或数字,最多128个字符");
        }
    }

}
